package com.gzx.risk.core.apis.context;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.gzx.risk.core.apis.result.MainResult;
import com.gzx.risk.core.apis.result.RiskResult;
import com.gzx.risk.core.pojo.OrderInfo;
import com.gzx.risk.core.pojo.UserInfo;

import lombok.Data;

@Data
public class ApiContext {
	private OrderInfo order;
	private UserInfo userInfo;
	private String lastRefuseDate;// 系统最后一次拒绝时间
	private String authDate;
	private List<RiskResult> results = Lists.newArrayList();// api获取数据

	public void add(RiskResult result) {
		result.setOrder(String.valueOf(results.size()));
		results.add(result);
		result.setDataContent(JSONObject.toJSONString(result));
	}

	private String groupName;// 规则组名
	private String dataName;
	private Boolean ruleResult = true;// 默认通过
	private String rejectRule;
	private String rejectMsg;
	private Integer yushouCount;// 预收期数

	public MainResult getMainResult() {
		MainResult mainResult = new MainResult();
		mainResult.setName(userInfo.getName());
		mainResult.setId(userInfo.getId());
		mainResult.setPhone(userInfo.getPhone());
		mainResult.setAuthDate(userInfo.getAuthDate());
		mainResult.setIdLastdate(userInfo.getIdLastdate());
		mainResult.setLastRefuseDate(lastRefuseDate);
        mainResult.setCity(order.getCity());
		return mainResult;
	}

	public void update(RiskResult result) {
		result.setRuleResult(ruleResult);
		result.setRejectRule(rejectRule);
		result.setRejectMsg(rejectMsg);
		this.groupName = result.getGroupName();
		this.dataName = result.getDataName();
	}
}
